package com.movie.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.movie.model.auto.ScoreAccount;
import com.movie.model.auto.UserScore;
import com.movie.model.auto.UserScoreAccount;
import com.movie.service.impl.UserScoreServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户评分表 前端控制器
 * </p>
 *
 * @author 达瓦里氏
 * @since 2021-12-16
 */
@RestController
@RequestMapping("/score")
@CrossOrigin
public class UserScoreController {

    @Resource
    private UserScoreServiceImpl userScoreService;

    /*查询评分表*/
    @GetMapping("/getUserScore")
    public List<UserScoreAccount> getUserScore() {
        return userScoreService.SelectAllScore();
    }

    /*通过id查询评分表*/
    @GetMapping("/getUserScoreById/{id}")
    public UserScoreAccount getUserScoreById(@PathVariable("id") int id) {
        return userScoreService.SelectScoreById(id);
    }

    /*修改评分表*/
    @PostMapping("/updateUserScore")
    public void updateUserScore(@RequestBody UserScore userScore) {
        userScoreService.updateById(userScore);
    }

    /*添加评分表*/
    @PostMapping("/setUserScore")
    public void setUserScore(@RequestBody UserScore userScore) {
        userScoreService.save(userScore);
    }

    /*删除评分表*/
    @PostMapping("/deletedById/{id}")
    public boolean deleted(@PathVariable("id") int id) {
        return userScoreService.removeById(id);
    }

    /*批量删除评分表*/
    @PostMapping("/deletedAllById")
    public boolean deletedAllById(@RequestBody int[] delarr){
        for (int i : delarr) {
            System.out.println(i);
            userScoreService.removeById(i);
        }
        return true;
    }

    /*模糊查询用户数据*/
    @PostMapping("/selectScore/{input}")
    public List<UserScoreAccount> selectUser(@PathVariable("input") String value){
            return userScoreService.SelectScoreByName(value);
    }

    /*根据名称查询用户*/
    @GetMapping("/selectByName/{name}")
    public List<UserScoreAccount> selectByName(@PathVariable("name") String name){
        return userScoreService.SelectByName(name);
    }

    /*根据电影id批量查询评论*/
    @GetMapping("/getScoreById/{id}")
    public List<ScoreAccount> getScoreById(@PathVariable("id")int id){
        return userScoreService.getScoreById(id);
    }


}
